a11y: Fix focusable state
authorMatthias Clasen <mclasen@redhat.com>
Thu, 9 Apr 2020 21:50:02 +0000 (17:50 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 9 Apr 2020 22:14:15 +0000 (18:14 -0400)
The :can-focus property is no longer very useful to
give an indication of what is focusable, since it is
TRUE for almost all widgets now. Patch things up
to by looking at known widget types.

gtk/a11y/gtkwidgetaccessible.c

index 38f96c8b7db6bf31a65f14dc78c1772e915f3a95..84732dcda59c10793053a39e79a89cdac04ef563 100644 (file)
@@ -293,6 +293,36 @@ gtk_widget_accessible_ref_relation_set (AtkObject *obj)
   return relation_set;
 }
 
+static gboolean
+takes_focus (GtkWidget *widget)
+{
+  if (GTK_IS_NOTEBOOK (widget) ||
+      GTK_IS_BUTTON (widget))
+    return TRUE;
+
+  if (GTK_IS_ACCEL_LABEL (widget) ||
+      GTK_IS_CONTAINER(widget) ||
+      GTK_IS_DRAG_ICON (widget) ||
+      GTK_IS_DRAWING_AREA (widget) ||
+      GTK_IS_GL_AREA (widget) ||
+      GTK_IS_IMAGE (widget) ||
+      GTK_IS_LEVEL_BAR (widget) ||
+      GTK_IS_MEDIA_CONTROLS (widget) ||
+      GTK_IS_PICTURE (widget) ||
+      GTK_IS_PROGRESS_BAR (widget) ||
+      GTK_IS_SCROLLBAR (widget) ||
+      GTK_IS_SEPARATOR (widget) ||
+      GTK_IS_SHORTCUT_LABEL (widget) ||
+      GTK_IS_SHORTCUTS_SHORTCUT (widget) ||
+      GTK_IS_SPINNER (widget) ||
+      GTK_IS_STACK_SIDEBAR (widget) ||
+      GTK_IS_STATUSBAR (widget) ||
+      GTK_IS_VIDEO (widget))
+    return FALSE;
+
+  return gtk_widget_get_can_focus (widget);
+}
+
 static AtkStateSet *
 gtk_widget_accessible_ref_state_set (AtkObject *accessible)
 {
@@ -312,7 +342,7 @@ gtk_widget_accessible_ref_state_set (AtkObject *accessible)
           atk_state_set_add_state (state_set, ATK_STATE_ENABLED);
         }
   
-      if (gtk_widget_get_can_focus (widget))
+      if (takes_focus (widget))
         {
           atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
         }